package com.gcd.tempe;

import com.gcd.tempe.R;
import com.gcd.tempe.model.Barang;
import com.gcd.tempe.model.UserLogin;
import com.gcd.tempe.util.GlobalVariabel;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;

public class MainTEMPE extends Activity {
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        if (LoginActivity.username==null) { //Belum Login
        	//Menu cart diilangin
        	View b = findViewById(R.id.button4);
        	b.setVisibility(View.GONE);
        	
        	//Menu logout diilangin
        	View b2 = findViewById(R.id.buttonLogout);
        	b2.setVisibility(View.GONE);
        	
        	//Menu History Pesanan diilangin
        	View b3 = findViewById(R.id.button5);
        	b3.setVisibility(View.GONE);
        } else { //Udah Login
        	//Menu Login diilangin
        	View b3 = findViewById(R.id.button1);
        	b3.setVisibility(View.GONE);
        	
        	//Menu lihat barang diturunin
        	View b4 = findViewById(R.id.button2);
        	LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            llp.setMargins(0, 165, 0, 0);
            llp.gravity =  Gravity.CENTER;
            b4.setLayoutParams(llp);
        }
        
        
        //DUMMY
        //Barang itemAdded = new Barang(1, 1, "Dummy", "dodol", "deskripsi", 20000 , 2);
		//GlobalVariabel.cartItems.addItemToItemsCart(itemAdded);
    }
    
    public void btnLogin(View v) {
    	Intent intent = new Intent(this, LoginActivity.class);
    	startActivity(intent);
    }
    
    public void btnLihatBarang(View v){
    	Intent intent = new Intent(this, LihatBarangActivity.class);
    	startActivity(intent);
    }
    
    public void btnLihatCartClick(View v) {
    	Intent intent = new Intent(this, LihatCartActivity.class); //intent lihatcart
    	startActivity(intent);
    }
    
    public void btnLogoutClick(View v) {
    	LoginActivity.username = null;
    	LoginActivity.password = null;
    
    	Toast.makeText(MainTEMPE.this, "Anda telah berhasil logout!", Toast.LENGTH_SHORT).show();
    	Intent intent = new Intent(this, MainTEMPE.class); //intent lihatcart
    	startActivity(intent);
    }
    
    public void btnLihatHistoryPesananClick(View v) {
    	Intent intent = new Intent(this, LihatHistoryPesananActivity.class); //intent lihatcart
    	startActivity(intent);
		
	}
}